
#ifndef __IO_ENGINE_H__
#define __IO_ENGINE_H__
#include "log.h"

#ifdef __cplusplus

class IOEngine;
extern IOEngine* ng_pio;			// powered by pread()、pwrite() family
//extern IOEngine* ng_posix_aio;		// powered by posix aio
extern IOEngine* ng_libaio;			// powered by libaio
extern IOEngine* ioengine;			// the chosen IOEngine, default: ng_pio

class IOEngine
{
public:
	virtual ssize_t pread(int fd, void *buf, size_t count, off_t offset)=0;
	virtual ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)=0;
	virtual ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)=0;
	virtual ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)=0;
	virtual int fdatasync(int fd)=0;
	virtual int fsync(int fd)=0;

protected:
	IOEngine() { LOG_DEBUG("IOEngine constructor run"); }
	virtual ~IOEngine() { LOG_DEBUG("IOEngine destructor run"); }
};

#endif

#ifdef __cplusplus
extern "C" {
#endif

void enable_libaio(void);
//void enable_posix_aio(void);
void enable_ignore_ops(void);

#ifdef __cplusplus
}
#endif

#endif
